#!/bin/python

from subprocess import call
import random
import sys

sys.stdout = open('python_output.txt', 'w')

def randomfloats(numfragments):
    sum = 0.0
    count = 0.0
    call(["mkdir", "files" + numfragments])
    for i in range(int(numfragments)):
        f = open('files' + numfragments + '/file-' + str(i+1) + '.txt', 'w')
        
        for i in range(5):
            val = random.uniform(0.0, 1000.0)
            count = count + 1
            sum = val + sum
            f.write(str(val) + '\n')
        
        f.flush()
    
    print("Average\t" + str(sum / count))
    print("Created files")

machines = "\"inst1@Adams-MacBook-Air.local,inst2@Adams-MacBook-Air.local\""

print("Servers,File Fragments,Numbers,% Correct,Average Gossip Cycles,Program Run Time")
    
for files in [16,32,64,128,256,512,1024,2048,4096,8192,16384]:
    randomfloats(str(files))
    for nodes in [16,32,64,128,256,512,1024,2048,4096,8192,16384]:
        for replication in [4,8,16,32]:
            for neighbors in range(1,15):
                print("NEW TEST," + str(nodes) + "," + str(files) + "," + str(replication) + "," + str(neighbors))
                call(["sh", "prj2test.sh", "inst3", str(nodes), "\"files" + str(files) + "\"", str(replication), str(neighbors), machines], stdout=sys.stdout)
